Python dataclasses._create_fn
https://github.com/python/cpython/blob/v3.10.5/Lib/dataclasses.py#L412-L435
位置引数は3つ
name
args
body
文字列を作ってexecする
Python 組み込み関数 exec
code:execされる文字列.py
# f-stringにより変数が埋め込まれる
def __create_fn__({local_vars}):
def {name}({args}){return_annotation}:
body
return {name}
ns['__create_fn__'](**locals)をreturn
nsは空の辞書でexecのlocals引数に渡る
The only callers are internal to this module, so no worries about external callers.
dataclassesの_create_fnを完全に理解する